package com.fdb.efp.limit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.fdb.efp.limit.service.dao.LmtPrelistHandoverAppDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.limit.service.domain.LmtPrelistHandoverApp;
import com.fdb.efp.limit.service.facade.LmtPrelistHandoverAppService;
import com.fdb.efp.limit.service.vo.LmtPrelistHandoverAppVO;

/**
 * <p>
 * 白名单移交申请表的Service实现类
 * </p>
 * @author szbd
 * @createDate 2018-07-31 09:19:42
 */
@Service("lmtPrelistHandoverAppService")
public class LmtPrelistHandoverAppServiceImpl implements LmtPrelistHandoverAppService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(LmtPrelistHandoverAppServiceImpl.class);
    
    @Autowired
    private LmtPrelistHandoverAppDao lmtPrelistHandoverAppDao;
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverAppVO> queryAllOwner(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("查询本人所属的白名单移交申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverApp> dataList = lmtPrelistHandoverAppDao.queryAllOwnerByPage(inLmtPrelistHandoverAppVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverAppVO> resultList = new ArrayList<LmtPrelistHandoverAppVO>();
                resultList = (List<LmtPrelistHandoverAppVO>) beansCopy(dataList, LmtPrelistHandoverAppVO.class);
                pageSet(resultList, inLmtPrelistHandoverAppVo);
                return resultList;
            } else {
                logger.info("查询本人所属的白名单移交申请表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本人所属的白名单移交申请表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverAppVO> queryAllCurrOrg(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("查询本机构的白名单移交申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverApp> dataList = lmtPrelistHandoverAppDao.queryAllCurrOrgByPage(inLmtPrelistHandoverAppVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverAppVO> resultList = new ArrayList<LmtPrelistHandoverAppVO>();
                resultList = (List<LmtPrelistHandoverAppVO>) beansCopy(dataList, LmtPrelistHandoverAppVO.class);
                pageSet(resultList, inLmtPrelistHandoverAppVo);
                return resultList;
            } else {
                logger.info("查询本机构的白名单移交申请表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构的白名单移交申请表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverAppVO> queryAllCurrDownOrg(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("查询本机构及下属机构的白名单移交申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverApp> dataList = lmtPrelistHandoverAppDao.queryAllCurrDownOrgByPage(inLmtPrelistHandoverAppVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverAppVO> resultList = new ArrayList<LmtPrelistHandoverAppVO>();
                resultList = (List<LmtPrelistHandoverAppVO>) beansCopy(dataList, LmtPrelistHandoverAppVO.class);
                pageSet(resultList, inLmtPrelistHandoverAppVo);
                return resultList;
            } else {
                logger.info("查询本机构及下属机构的白名单移交申请表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构及下属机构的白名单移交申请表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public int insertLmtPrelistHandoverApp(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("新增白名单移交申请表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverApp lmtPrelistHandoverApp = new LmtPrelistHandoverApp();
            beanCopy(inLmtPrelistHandoverAppVo, lmtPrelistHandoverApp);
            count = lmtPrelistHandoverAppDao.insertLmtPrelistHandoverApp(lmtPrelistHandoverApp);
        } catch (Exception e) {
            logger.error("新增白名单移交申请表数据发生异常！", e);
            count = -1;
        }
        logger.info("当前新增白名单移交申请表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteLmtPrelistHandoverAppByPk(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("删除白名单移交申请表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverApp lmtPrelistHandoverApp = new LmtPrelistHandoverApp();
            beanCopy(inLmtPrelistHandoverAppVo, lmtPrelistHandoverApp);
            count = lmtPrelistHandoverAppDao.deleteLmtPrelistHandoverAppByPk(lmtPrelistHandoverApp);
        } catch (Exception e) {
            logger.error("删除白名单移交申请表数据发生异常！", e);
            count = -1;
        }
        logger.info("删除的白名单移交申请表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int updateLmtPrelistHandoverAppByPk(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("修改白名单移交申请表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverApp lmtPrelistHandoverApp = new LmtPrelistHandoverApp();
            beanCopy(inLmtPrelistHandoverAppVo, lmtPrelistHandoverApp);
            count = lmtPrelistHandoverAppDao.updateLmtPrelistHandoverAppByPk(lmtPrelistHandoverApp);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.info("修改的白名单移交申请表数据条数为" + count);
        return count;
    }
    
    @Override
    public LmtPrelistHandoverAppVO queryLmtPrelistHandoverAppByPk(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("根据主键查询白名单移交申请表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            LmtPrelistHandoverApp lmtPrelistHandoverApp = new LmtPrelistHandoverApp();
            beanCopy(inLmtPrelistHandoverAppVo, lmtPrelistHandoverApp);
            lmtPrelistHandoverApp = lmtPrelistHandoverAppDao.queryLmtPrelistHandoverAppByPk(lmtPrelistHandoverApp);
            if (Objects.nonNull(lmtPrelistHandoverApp)) {
                LmtPrelistHandoverAppVO outLmtPrelistHandoverAppVo = beanCopy(lmtPrelistHandoverApp, new LmtPrelistHandoverAppVO());
                return outLmtPrelistHandoverAppVo;
            } else {
                logger.info("根据主键查询白名单移交申请表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询白名单移交申请表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public LmtPrelistHandoverAppVO querySingleLmtPrelistHandoverAppByCondition(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("根据条件查询单笔白名单移交申请表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            LmtPrelistHandoverApp lmtPrelistHandoverApp = new LmtPrelistHandoverApp();
            beanCopy(inLmtPrelistHandoverAppVo, lmtPrelistHandoverApp);
            lmtPrelistHandoverApp = lmtPrelistHandoverAppDao.querySingleLmtPrelistHandoverAppByCondition(lmtPrelistHandoverApp);
            if (Objects.nonNull(lmtPrelistHandoverApp)) {
                LmtPrelistHandoverAppVO outLmtPrelistHandoverAppVo = beanCopy(lmtPrelistHandoverApp, new LmtPrelistHandoverAppVO());
                return outLmtPrelistHandoverAppVo;
            } else {
                logger.info("根据条件查询单笔白名单移交申请表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据条件查询单笔白名单移交申请表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverAppVO> queryLmtPrelistHandoverAppByCondition(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("条件查询白名单移交申请表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverApp> dataList = lmtPrelistHandoverAppDao.queryLmtPrelistHandoverAppByCondition(inLmtPrelistHandoverAppVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverAppVO> resultList = new ArrayList<LmtPrelistHandoverAppVO>();
                resultList = (List<LmtPrelistHandoverAppVO>) beansCopy(dataList, LmtPrelistHandoverAppVO.class);
                return resultList;
            } else {
                logger.info("条件查询白名单移交申请表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件查询白名单移交申请表发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverAppVO> queryLmtPrelistHandoverAppByConditionByPage(LmtPrelistHandoverAppVO inLmtPrelistHandoverAppVo) {
        logger.info("条件分页查询白名单移交申请表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverAppVo));
        if(Objects.isNull(inLmtPrelistHandoverAppVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverApp> dataList = lmtPrelistHandoverAppDao.queryLmtPrelistHandoverAppByConditionByPage(inLmtPrelistHandoverAppVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverAppVO> resultList = new ArrayList<LmtPrelistHandoverAppVO>();
                resultList = (List<LmtPrelistHandoverAppVO>) beansCopy(dataList, LmtPrelistHandoverAppVO.class);
                pageSet(resultList, inLmtPrelistHandoverAppVo);
                return resultList;
            } else {
                logger.info("条件分页查询白名单移交申请表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件分页查询白名单移交申请表发生异常！", e);
        }
        return null;
    }
}